using System;

namespace TagTool.Devices.Midi
{
    /// <summary> Represents a midi channel message </summary>
    public class MidiChannelMessage : IChannelMessage
    {
        /// <summary> Status, channel and data bits </summary>
        private uint highData;
        /// <summary> Timestamp </summary>
        private uint lowData;

        /// <summary> Default constructor </summary>
        /// <param name="highData"> Parameter with data, usually status, channel and data bits </param>
        /// <param name="lowData"> Parameter with data, usually a timestamp </param>
        public MidiChannelMessage(uint highData, uint lowData)
        {
            this.highData = highData;
            this.lowData = lowData;
        }

        /// <summary> Property HighData </summary>
        public uint HighData
        {
            get
            {
                return highData;
            }
        }

        /// <summary> Property LowData </summary>
        public uint LowData
        {
            get
            {
                return lowData;
            }
        }

        /// <summary> Property Status </summary>
        /// <remarks> Status can be found in the 4 upper bits of the first byte in highData </remarks>
        public uint Status
        {
            get
            {
                return (highData & (uint)MidiMessageMask.LowMask);
            }
        }

        /// <summary> Property Channel </summary>
        /// <remarks> Channel number is in the 4 lower bits of the first byte in highData </remarks>
        public uint Channel
        {
            get
            {
                return (highData & (uint)MidiMessageMask.HighMask) + 1;
            }
        }

        /// <summary> Property TimeStamp </summary>
        /// <remarks> TimeStamp is in lowData </remarks>
        public uint TimeStamp
        {
            get
            {
                return lowData;
            }
        }
    }
}
